package com.htgd.gardenexpo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.dao.GeConSceneDao;
import com.htgd.gardenexpo.entity.GeConScene;
import com.htgd.gardenexpo.page.SceneQuery;
import com.htgd.gardenexpo.service.GeBaseDictService;
import com.htgd.gardenexpo.service.GeConSceneService;
import com.htgd.gardenexpo.service.WxUserCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 景区百科表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-05-08
 */
@Service
public class GeConSceneServiceImpl extends ServiceImpl<GeConSceneDao, GeConScene> implements GeConSceneService {

    @Autowired
    private GeConSceneDao geConSceneDao;

    @Autowired
    private GeBaseDictService geBaseDictService;

    @Autowired
    private WxUserCollectService wxUserCollectService;

    @Override
    public PageInfo<GeConScene> queryList(SceneQuery sceneQuery, String openId) {
        PageHelper.startPage(sceneQuery.getPageNum(), sceneQuery.getPageSize());
        List<GeConScene> list = geConSceneDao.querylist(sceneQuery);
        list.stream().forEach(item->{
            item.setRecommendTypeText(geBaseDictService.getRecommendTypeText(item.getRecommendType()));
            if(Objects.equals(item.getHot(),"0")) item.setHotText("普通");
            if(Objects.equals(item.getHot(),"1")) item.setHotText("热门");

            Boolean collect = wxUserCollectService.isLike(openId, String.valueOf(item.getId()),"scene");
            if (collect) {
                item.setIsLike(true);
            }else{
                item.setIsLike(false);
            }
        });
        return new PageInfo<>(list);
    }

}
